home *** CD-ROM | disk | FTP | other *** search
/ Cracking 2 / Cracking II..iso / Texty / crackme / phox1-c.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-05  |  2.9 KB  |  85 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <io.h>
  4.  
  5. struct infostruct {
  6.   char *filename;
  7.   unsigned long filesize;
  8.   unsigned long ps_size;
  9. };
  10.  
  11. struct patchstruct {
  12.   unsigned long pos;
  13.   unsigned char old_byte;
  14.   unsigned char new_byte;
  15. };
  16.  
  17. int do_patch(struct infostruct is, struct patchstruct ps[]);
  18.  
  19. #define PATCHSIZE_1 5
  20. struct infostruct is_1 = { "crackme1.exe" , 0x2000 , PATCHSIZE_1 };
  21. struct patchstruct ps_1 [PATCHSIZE_1] = {
  22.   { 0x61E, 0xE8, 0x90 },
  23.   { 0x61F, 0xDA, 0x90 },
  24.   { 0x620, 0x01, 0x90 },
  25.   { 0x621, 0x00, 0x90 },
  26.   { 0x622, 0x00, 0x90 },
  27. };
  28.  
  29. int main(void) {
  30.   printf("   ▄▄▄                                                               ▓▄  ▄\n");
  31.   printf("  ▀██▓▀        ▓          ▓▄▄ ▄▓▀▀▀ ▀  ▄▄  ▓▄▄▄▄▓           ▓▄▄▄▄▄▓▀▀▀ ▄▄▄\n");
  32.   printf(" ░  ▄▄▄  ▄▄▓▀▀▀▀ ▀▀▓▄▄ ▓▀▀▀ ▄▄▄▄▄███▌ ▀██▀ ▄▄▄▄ ▀ ▀▓▄▄▓  ▓▀▀▀ ▄▄▄▄▄▄███▓█▌\n");
  33.   printf("  ▀▓██▌ ▓▀ ▄▄█████▄▄ ▓  ▄█▓████▀▀███ ░ ▄▄▄ ▐██████▄▄▄ ▀▀▓▀▐█████▀▀▀▀████▀\n");
  34.   printf("   ████ ■ ████▀  ▀███▄ ▓████▄  ░ ▀▀ ▓ ████░ █▓█▌ ▀▀████▄▄  ▓███ ░  ▀▀▀\n");
  35.   printf("  ■▐███▌ ▐▓██▌░ ▓ ▐███▌ ▀▀██████▄▄▄▄  ▐█▓█▌ █▓█▌ ▄ ░ ▀▀███▄ ███▌ ▄▄▄▄\n");
  36.   printf("  ▄ ██▓█ ████▌■ ▐▌ █▓██ ▓▄▄▄  ▀▀▀▀███▓▄▀███ ▐███ ▓    ░ ▀██▓▄▀█▌▀▀▀   MtD! ▄\n");
  37.   printf("  ▓ ███▓▌▀▓██ ▄  █ ▐▓▓█▌   ▀▀▀▀  ▄▄███▓▌███▌▐█▓█ ▄▄▀▀ ▀ ▄███▓▌█▓  ░\n");
  38.   printf("  ▐▌▐████ ▀▀▀ ▄  ▓ ▐█▓█▌▐███▄▄███████▓▀ ██▓▌▀▀ ▄▄▄▄▄██████▓▀▀▄██▄▄▄▄▄██▓▓▌ ▀\n");
  39.   printf("  █ ▀▀▀ ▄▄▓ ▀▀▓  ▓ ▀▀▀▀ ▓███▀▀▀▀▀ ▄▄▄  ▀▀▀▀ ▀█████▀▀▀▀▀ ▄ ▄ █████▀▀▀▀▀██▓█ █\n");
  40.   printf(" ▀▓ ▀▀▀▀▓   ▀   ▀▀ ▀▀▀▓▄▄▄ ▄▄▓▀▀▀▀▓   ▓▀▀▀ ▀  ▀▀█▄ ▀▀▀▀▀▓▀▓▄▄▄ ▄▄▄▓▀▓▄ ▄▄▄▄▓\n");
  41.   printf("                                                   ▀                ▀      ▀\n");
  42.   printf("                  Phox Crackme 1.0 patch by Duelist of iNSiDE99.            \n");
  43.   printf("\n");
  44.   do_patch(is_1, ps_1);
  45.   printf("\n");
  46.   printf("                      iNSiDE99, bringing you TRUE quality.                  \n");
  47.   return 0;
  48. }
  49.  
  50. int do_patch(struct infostruct is, struct patchstruct ps[]) {
  51.   int handle;
  52.   unsigned long counter;
  53.   unsigned char value;
  54.  
  55.   printf("  checking for %s... ", is.filename);
  56.  
  57.   if ((handle = open(is.filename, O_RDWR | O_BINARY)) == -1) {
  58.     printf("not found.\n");
  59.     return -1;
  60.   } else printf("found... ");
  61.  
  62.   if (filelength(handle) != is.filesize) {
  63.     printf("incorrect filesize.\n");
  64.     return -1;
  65.   } else printf("now patching... ");
  66.  
  67.   for (counter=0; counter<is.ps_size; counter++) {
  68.     lseek(handle, ps[counter].pos, SEEK_SET);
  69.     read(handle, &value, 1);
  70.     if (value != ps[counter].old_byte) {
  71.       if (value == ps[counter].new_byte) {
  72.         printf("file already patched.\n");
  73.         return -2;
  74.       }
  75.       printf("incompatible file.\n");
  76.       return -2;
  77.     }
  78.     lseek(handle, ps[counter].pos, SEEK_SET);
  79.     write(handle, &ps[counter].new_byte, 1);
  80.   }
  81.   printf("done.\n");
  82.   close(handle);
  83.   return 0;
  84. }
  85.